import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-04-19
 * Time: 17:37
 */
class Com implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2 - o1;//大堆
    }
}

public class HeapTest {
    public static void main(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Com());
        queue.offer(1);
    }

    public static void InsertSort(int[] a) {
        for (int i = 1; i <= a.length - 1; i++) {
            int j = i - 1;
            int tmp = a[i];
            while (j >= 0) {
                if (a[j] > tmp) {
                    a[j + 1] = a[j];
                    j--;
                } else {
                    a[j + 1] = tmp;
                    break;
                }
            }
            a[j + 1] = tmp;
        }
    }

    public static void main2(String[] args) {
        int[] a = {2, 9, 5, 1, 7, 4, 8, 6, 3, 5};
        System.out.println(Arrays.toString(a));
        InsertSort(a);
        System.out.println(Arrays.toString(a));
    }

    public static void main1(String[] args) {
        int[] array = {27, 15, 19, 18, 28, 34, 65, 49, 25, 37};
        Heap heap = new Heap(array);
/*        heap.createMaxHeap(array);//创建大根堆
        System.out.println("大根堆" + heap);
        heap.offerMax(90);
        System.out.println("大根堆,插入" + heap);
        System.out.println(heap.poolMax());
        System.out.println("大根堆,删除" + heap);*/
        System.out.println("===========");
        heap.createMinHeap(array);//创建小根堆
        System.out.println("小根堆" + heap);
        heap.offerMin(9);
        System.out.println("小根堆,插入" + heap);
        System.out.println(heap.poolMin());
        System.out.println("小根堆,删除" + heap);
    }
}
